namespace KinonekoSoftware.CodariaDB.Documents.Impressions
{
    public sealed class ImpressionEngine : _Full<Impression>
    {
        public override string GetCollectionName() => CollectionNames.ImpressionDB;
        
        public void AddImpression(Impression impression)
        {
            if (string.IsNullOrEmpty(impression?.Id))
            {
                return;
            }

            InsideDB.Insert(impression);
        }
        
        public void Update(Impression impression)
        {
            if (string.IsNullOrEmpty(impression?.Id))
            {
                return;
            }

            InsideDB.Update(impression);
        }
        
        public void RemoveImpression(Impression impression)
        {
            
            if (string.IsNullOrEmpty(impression?.Id))
            {
                return;
            }

            InsideDB.Delete(impression.Id);
        }
        
        public void RemoveImpression(string id)
        {
            
            if (string.IsNullOrEmpty(id))
            {
                return;
            }

            //
            //
            var removeItems = InsideDB.Find(x => x.DocumentID == id).Select(x => x.Id).ToHashSet();

            //
            //
            InsideDB.DeleteMany(x => removeItems.Contains(x.DocumentID));
        }

        
        public IEnumerable<Impression> GetImpressions(string id) => InsideDB.Find(x => x.DocumentID == id);

        public override string EngineID => EngineNames.Keyword;
    }
}